package com.drinks.yiniang.adapter.category;

import android.content.Context;
import android.support.annotation.Nullable;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.drinks.yiniang.R;
import com.drinks.yiniang.adapter.base.BaseQuickRCVAdapter;
import com.drinks.yiniang.entity.category.SubCategoryJson;
import com.hansen.library.utils.CommonUtils;

import java.util.List;

/**
 * 子分类数据adapter
 * @author han
 * @date 2019/8/30
 */
public class SubCategoryLeftAdapter extends BaseQuickRCVAdapter<SubCategoryJson.SubCategoryList, BaseViewHolder> {

    private TextView mTvName;

    //当前选中的pos
    private int mCurrentChoosePos = -1;

    public SubCategoryLeftAdapter(Context mContext, @Nullable List<SubCategoryJson.SubCategoryList> data) {
        super(R.layout.item_sub_category_left, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, SubCategoryJson.SubCategoryList item) {
        mTvName = helper.getView(R.id.tv_sub_category_left_name);

        mTvName.setText(item.getName());
        mTvName.setSelected(item.isChecked());
    }

    public int getCurrentChoosePos() {
        return mCurrentChoosePos;
    }

    public void setCurrentChoosePos(int currentChoosePos) {
        SubCategoryJson.SubCategoryList data = getItem(mCurrentChoosePos);

        if(data != null) {
            data.setChecked(false);
            setData(mCurrentChoosePos, data);
        }

        data = getItem(currentChoosePos);

        if(data != null) {
            data.setChecked(true);
            setData(currentChoosePos, data);
        }

        this.mCurrentChoosePos = currentChoosePos;
    }
}
